package cn.wh.pay.type.ltzf.config;

import cn.wh.pay.configuration.PayConfig;
import cn.wh.pay.factory.PayFactory;
import cn.wh.pay.factory.defaults.LtzfPayFactory;
import cn.wh.pay.type.ltzf.payments.app.AppPayService;
import cn.wh.pay.type.ltzf.payments.h5.H5PayService;
import cn.wh.pay.type.ltzf.payments.jsapi.JSPayService;
import cn.wh.pay.type.ltzf.payments.nativepay.NativePayService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author wh
 * @Description 环境自动装配
 * @Date 2024/4/23 9:38
 * @Version 1.0
 **/

@Configuration
@EnableConfigurationProperties(PayConfig.class)
@ConditionalOnProperty(value = "pay.config.payType", havingValue = "ltzf")
public class LtzfAutoConfig{


    @Bean("ltzfConfiguration")
    public LtzfConfiguration ltzfConfiguration(PayConfig payConfig) {
        LtzfConfiguration ltzfConfiguration = new LtzfConfiguration(payConfig);
        return ltzfConfiguration;
    }

    @Bean("ltzfFactory")
    public PayFactory ltzfFactory(LtzfConfiguration ltzfConfiguration) {
        PayFactory ltzfFactory = new LtzfPayFactory(ltzfConfiguration);
        return ltzfFactory;
    }


    @Bean("nativePayService")
    public NativePayService nativePayService(PayFactory ltzfFactory) {
        return ltzfFactory.nativePayService();
    }


    @Bean("h5PayService")
    public H5PayService h5PayService(PayFactory ltzfFactory) {
        return ltzfFactory.h5PayService();
    }

    @Bean("appPayService")
    public AppPayService appPayService(PayFactory ltzfFactory) {
        return ltzfFactory.appPayService();
    }

    @Bean("jsPayService")
    public JSPayService jsPayService(PayFactory ltzfFactory) {
        return ltzfFactory.jsPayService();
    }


}
